<template>
  <div class="year-box">
    <div class="title">
      <p>年度游客量对比</p>
      <p class="bg" />
    </div>
    <div ref="charts" class="echarts-box" />
  </div>
</template>

<script setup lang="ts" name="Year">
import * as echarts from 'echarts';
import { onMounted, ref } from 'vue';

let charts = ref();

onMounted(() => {
  let mycharts = echarts.init(charts.value);
  let options = {
    title: {
      text: '(人数)',
      textStyle: {
        color: '#fff',
        fontSize: 12,
      },
    },
    xAxis: {
      //   type: 'category',
      boundaryGap: false,
      data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
      splitLine: {
        show: false,
      },
      axisLabel: {
        color: '#fff',
      },
    },
    yAxis: {
      splitLine: {
        show: false,
      },
      axisLine: {
        show: true,
      },
      axisTick: {
        show: true,
      },
      axisLabel: {
        color: '#fff',
      },
    },
    //调整图形图标的位置
    grid: {
      left: 45,
      top: 30,
      right: 20,
      bottom: 20,
    },
    legend: {
      show: true,
      data: ['2022年', '2023年', '2024年'],
      right: 10,
      itemSyle: {
        // color: 'inherit',
      },
      textStyle: {
        color: '#fff',
      },
    },
    series: [
      {
        name: '2024年',
        type: 'line',
        data: [693, 555, 467, 325, 582, 333, 435, 111, 333, 435, 111, 333],
        smooth: true,
        lineStyle: {
          color: '#FF4B7A',
        },
        itemStyle: {
          color: '#FF4B7A',
        },
        symbol: 'none',
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: '#FF4B7A', // 0% 处的颜色
              },
              {
                offset: 1,
                color: '#FF4B7A09', // 100% 处的颜色
              },
            ],
            global: false, // 缺省为 false
          },
        },
      },
      {
        name: '2022年',
        type: 'line',
        data: [300, 200, 670, 323, 546, 234, 567, 372, 268, 234, 300, 200],
        smooth: true,
        lineStyle: {
          color: '#FAC858',
        },
        itemStyle: {
          color: '#FAC858',
        },
        symbol: 'none',
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: '#FAC858', // 0% 处的颜色
              },
              {
                offset: 1,
                color: '#FAC85809', // 100% 处的颜色
              },
            ],
            global: false, // 缺省为 false
          },
        },
      },
      {
        name: '2023年',
        type: 'line',
        data: [333, 435, 111, 333, 693, 555, 467, 325, 582, 111, 333, 435],
        smooth: true,
        lineStyle: {
          color: '#005BCF',
        },
        itemStyle: {
          color: '#005BCF',
        },
        symbol: 'none',
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: '#005BCF', // 0% 处的颜色
              },
              {
                offset: 1,
                color: '#005BCF09', // 100% 处的颜色
              },
            ],
            global: false, // 缺省为 false
          },
        },
      },
    ],
  };
  mycharts.setOption(options);
});
</script>

<style lang="less" scoped>
.year-box {
  background: url('@/assets/images/screen/dataScreen-main-rb.png') no-repeat;
  background-size: 100% 100%;
  .title {
    color: white;
    font-size: 20px;
    .bg {
      width: 68px;
      height: 7px;
      background: url('@/assets/images/screen/dataScreen-title.png') no-repeat;
      background-size: 100% 100%;
      margin-top: 10px;
    }
  }
  .echarts-box {
    margin-top: 20px;
    height: calc(100% - 60px);
  }
}
</style>
